<template>
  <!-- 选择企业弹出层---默认单选 / isSingleSelect接收false时可多选 -->
  <el-dialog
    title="选择企业"
    :visible.sync="dialogVisible"
    width="1200px"
    append-to-body
    :close-on-click-modal="false"
    @close="close"
    class="self-dialog"
  >
    <el-form
      :model="queryParams"
      ref="queryVehicleForm"
      :inline="true"
      label-width="88px"
      size="mini"
    >
      <div class="sub-conditions">
        <div>
          <el-form-item label="企业名称：" prop="">
            <el-input
              v-model.trim="queryParams.coNameCn"
              placeholder="请输入商铺名称查询"
              clearable
            />
          </el-form-item>
          <el-button
            class="filter-item"
            type="warning"
            icon="el-icon-search"
            @click="getList"
            size="mini"
            >查询
          </el-button>
        </div>
      </div>
    </el-form>

    <basic-table
      ref="tableList"
      class="borderTable"
      :columns="columns"
      :tableData="tableData"
      :total="total"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
      :needCheckbox="true"
      @selectionChange="handleSelectionChange"
      :emptySmall="true"
    >
      <!-- 关区 -->
      <template #mainPort="scope">
        <dict-value
          :list="customsList"
          :dictCode="scope.row.mainPort"
        ></dict-value>
      </template>
      <!-- 企业备案类型 -->
      <template #coRecType="scope">
        <dict-value
          :list="dict.type.co_rec_type"
          :dictCode="scope.row.coRecType"
        ></dict-value>
      </template>
    </basic-table>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="sureShop">确 定</el-button>
      <el-button @click="close">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getCustomsList } from "@/api/bt/bmhs";
import { listCorporationInfo } from "@/api/swdecl/corporationInfo";
export default {
  name: "selectEnt",
  dicts: ["co_rec_type"],
  props: {
    isSingleSelect: {
      //true-控制只能单选， 为false时则为多选
      type: Boolean,
      default: true,
    },
  },
  created() {
    this.loadCustomsList();
  },
  data() {
    return {
      dialogVisible: false,
      //海关关区信息列表
      customsList: [],
      tableData: [],
      columns: [
        {
          prop: "coCode",
          label: "企业代码",
          align: "center"
        },
        {
          prop: "coNameCn",
          label: "企业中文名称",
          align: "center"
        },
        {
          prop: "coNameEn",
          label: "企业外文名称",
          align: "center"
        },
        {
          prop: "coRecType",
          label: "企业备案类别",
          align: "center",
          slot: true
        },
        {
          prop: "mainPort",
          label: "主管海关",
          align: "center",
          minWidth: 100,
          slot: true
        },
      ],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        coNameCn: "",
        // proposeStatus: "3",  //查询申报通过的数据
      },
      total: 0,
    };
  },
  methods: {
    /* 加载关区信息列表*/
    loadCustomsList() {
      getCustomsList().then(response => {
        this.customsList = response;
      });
    },
    getList() {
      listCorporationInfo(this.queryParams)
        .then((resp) => {
          this.tableData = resp.rows;
          this.total = resp.total;
        })
        .finally(() => {});
    },
    open() {
      this.dialogVisible = true;
      this.getList();
    },
    close() {
      this.dialogVisible = false;
    },
    // 分页
    handleSizeChange(val) {
      this.queryParams.pageSize = val.pageSize;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val.currentPage;
      this.getList();
    },
    handleSelectionChange(selection, val) {
      if (this.isSingleSelect) {
        if (selection.length > 1) {
          let del_row = selection.shift();
          this.$refs.tableList.$refs.table.toggleRowSelection(del_row, false);
        }
      }
      this.selectedBorder = selection;
    },
    sureShop() {
      if (this.selectedBorder.length > 0) {
        if (this.isSingleSelect) {
          this.$emit("handleSelected", this.selectedBorder[0]);
        } else {
          this.$emit("handleSelected", this.selectedBorder);
        }
        this.dialogVisible = false;
      } else {
        this.$message.warning("请先选择企业！");
      }
    },
  },
};
</script>

<style>
</style>
